# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest

import random
        
class SubGame_JoinRoom(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        btnAddRoom = poco("Button_AddRoom")
        if not btnAddRoom.exists():
            return False

        self.clickButton(btnAddRoom)

        addRoomLayer = poco("AddRoomLayer")
        if not addRoomLayer.exists():
            return False

        imgBoard = addRoomLayer.offspring("im_board")

        allNumItems = imgBoard.offspring(type="Button") 
        count = 0;
        while True:
            n = random.randint(0, 11)
            if not (allNumItems[n].offspring("Text_del").exists() or allNumItems[n].attr("name") == "reset_btn"):
                self.clickButton(allNumItems[n]) 
                count = count + 1
                if count == 6:
                    break               

        sleep(1.0)
        
        tipsLobbyLayer = poco("TipsLobbyLayer")
        btnSure = tipsLobbyLayer.offspring("Button_queding")
        self.clickButton(btnSure)

        btnClose = addRoomLayer.offspring("close_btn")
        self.clickButton(btnClose)

        return True
        
_instance = SubGame_JoinRoom()
runTest = _instance.runTest
